package likou.tanxin;

/**
 * @Info:
 * @Author: Tangxz
 * @Date: 2020/09/12 16:06
 */
public class _135 {
    public static void main(String[] args) {
        System.out.println(candy(new int[]{1,0,2}));
    }
    public static int candy(int[] ratings) {
        int[] dp = new int[ratings.length];
        dp[0] = 1;
        for (int i = 1; i < ratings.length; i++) {
            if (ratings[i] > ratings[i - 1]) {
                dp[i] = dp[i - 1] + 1;
            } else {
                dp[i] = 1;
            }
        }

        dp[0] = 1;
        for (int i = dp.length - 2; i >= 0; i--) {
            if (ratings[i] > ratings[i + 1] && dp[i] <= dp[i + 1]) {
                dp[i] = dp[i + 1] + 1;
            }
        }
        int amount = 0;
        for (int i = 0; i < ratings.length; i++) {
             System.out.print(dp[i] + " ");
            amount += dp[i];
        }
         System.out.println();
        return amount;
    }
}
